package 力扣日常刷题.木22二月.第06天212;

import java.util.Arrays;

/**
 * @author 帅小伙
 * @date 2022/2/12
 * @description
 */
public class Demo50贪心有效三角形的个数 {


    public int triangleNumber(int[] nums) {
        int ans = 0;
        int n = nums.length;
        Arrays.sort(nums);
        for (int i = 0; i < n; i++) {

            for (int j = i+1; j < n; j++) {
                int k = j;
                while(k+1 < n && nums[k+1] < nums[i] + nums[j])
                    k++;
                ans += Math.max(0,k - j);
            }
        }
        return ans;
    }
}
